//
//  ClinicTableViewCell.m
//  ybzj
//
//  Created by liyuan on 15/6/26.
//  Copyright (c) 2015年 liyuan. All rights reserved.
//

#import "ClinicTableViewCell.h"
#import "StarBar.h"
@interface ClinicTableViewCell ()
@property (weak, nonatomic) IBOutlet UIButton *ImageButton;
@property (weak, nonatomic) IBOutlet UIButton *StoreButton;
@property (weak, nonatomic) IBOutlet UIButton *DetailButton;
@property (weak, nonatomic) IBOutlet UILabel *TitleLabel;
@property (weak, nonatomic) IBOutlet StarBar *StarLabel;
@property (weak, nonatomic) IBOutlet UILabel *DistanceLabel;



@end


@implementation ClinicTableViewCell

-(void)awakeFromNib{
    self.contentView.layer.borderWidth=1.0f;
    self.contentView.layer.borderColor=[[UIColor grayColor] CGColor];
    self.ImageButton.layer.borderWidth=1.0f;
    self.ImageButton.layer.borderColor=[[UIColor grayColor] CGColor];
    CGFloat width=[UIScreen mainScreen].bounds.size.width;
    
    //set constrains for detailbutton
    _DetailButton.translatesAutoresizingMaskIntoConstraints=NO;
    NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:_DetailButton
                                                                      attribute:NSLayoutAttributeLeading
                                                                      relatedBy:NSLayoutRelationEqual
                                                                         toItem:self.contentView
                                                                      attribute:NSLayoutAttributeLeading
                                                                     multiplier:1.0f
                                                                       constant:width*508/640];
    

    
    NSLayoutConstraint* topConstraint = [NSLayoutConstraint constraintWithItem:_DetailButton
                                                                     attribute:NSLayoutAttributeBottom
                                                                     relatedBy:NSLayoutRelationEqual
                                                                        toItem:self.ImageButton
                                                                     attribute:NSLayoutAttributeBottom
                                                                    multiplier:1.0f
                                                                      constant:width*48/640];
    
  
    NSLayoutConstraint* heightConstraint = [NSLayoutConstraint constraintWithItem:_DetailButton
                                                                     attribute:NSLayoutAttributeHeight
                                                                     relatedBy:NSLayoutRelationEqual
                                                                        toItem:nil
                                                                     attribute:NSLayoutAttributeNotAnAttribute
                                                                    multiplier:1.0f
                                                                      constant:width*96/640];

    
    
   
    
    
    leftConstraint.active = YES;
    topConstraint.active = YES;
    heightConstraint.active = YES;
    _DetailButton.layer.cornerRadius=width*48/640;
    _DetailButton.layer.masksToBounds=YES;
    _DetailButton.layer.borderColor=[[UIColor whiteColor]CGColor];
    _DetailButton.layer.borderWidth= 2.0f;
    [_DetailButton setBackgroundImage:[UIImage imageNamed: @"doctor4.jpg"] forState:UIControlStateNormal];
    
    //set constrains for title label
    _TitleLabel.translatesAutoresizingMaskIntoConstraints=NO;
    NSLayoutConstraint *topConstranintforTitle = [NSLayoutConstraint constraintWithItem:_TitleLabel
                                                                              attribute:NSLayoutAttributeTop
                                                                              relatedBy:NSLayoutRelationEqual
                                                                                 toItem:self.contentView
                                                                              attribute:NSLayoutAttributeTop
                                                                             multiplier:1.0f
                                                                               constant:width*420/640];
    
    NSLayoutConstraint *bottomConstrainforTitle = [NSLayoutConstraint constraintWithItem:_TitleLabel
                                                                               attribute:NSLayoutAttributeBottom
                                                                               relatedBy:NSLayoutRelationEqual
                                                                                  toItem:self.contentView
                                                                               attribute:NSLayoutAttributeBottom
                                                                              multiplier:1.0f
                                                                                constant:0-width*64/640];
    
    NSLayoutConstraint *leftConstrainforTitle = [NSLayoutConstraint constraintWithItem:_TitleLabel
                                                                             attribute:NSLayoutAttributeLeading
                                                                             relatedBy:NSLayoutRelationEqual
                                                                                toItem:self.contentView
                                                                             attribute:NSLayoutAttributeLeading
                                                                            multiplier:1.0f
                                                                              constant:width*32/640];
    
    NSLayoutConstraint *rightConstrainforTitle = [NSLayoutConstraint constraintWithItem:_TitleLabel
                                                                              attribute:NSLayoutAttributeWidth
                                                                              relatedBy:NSLayoutRelationEqual
                                                                                 toItem:nil
                                                                              attribute:NSLayoutAttributeNotAnAttribute
                                                                             multiplier:1.0f
                                                                               constant:width*400/640];
    
    topConstranintforTitle.active=YES;
    bottomConstrainforTitle.active=YES;
    leftConstrainforTitle.active=YES;
    rightConstrainforTitle.active=YES;
    _TitleLabel.text=@"The Dental Studio";
    
    //set constrains for starlabel
    _StarLabel.translatesAutoresizingMaskIntoConstraints=NO;
    NSLayoutConstraint *topConstranintforStar = [NSLayoutConstraint constraintWithItem:_StarLabel
                                                                              attribute:NSLayoutAttributeTop
                                                                              relatedBy:NSLayoutRelationEqual
                                                                                 toItem:self.contentView
                                                                              attribute:NSLayoutAttributeTop
                                                                             multiplier:1.0f
                                                                               constant:width*460/640];
    
    NSLayoutConstraint *bottomConstrainforStar = [NSLayoutConstraint constraintWithItem:_StarLabel
                                                                               attribute:NSLayoutAttributeBottom
                                                                               relatedBy:NSLayoutRelationEqual
                                                                                  toItem:self.contentView
                                                                               attribute:NSLayoutAttributeBottom
                                                                              multiplier:1.0f
                                                                                constant:0-width*30/640];
    
    NSLayoutConstraint *leftConstrainforStar = [NSLayoutConstraint constraintWithItem:_StarLabel
                                                                             attribute:NSLayoutAttributeLeading
                                                                             relatedBy:NSLayoutRelationEqual
                                                                                toItem:self.contentView
                                                                             attribute:NSLayoutAttributeLeading
                                                                            multiplier:1.0f
                                                                              constant:width*32/640];
    
    NSLayoutConstraint *lengthConstrainforStar = [NSLayoutConstraint constraintWithItem:_StarLabel
                                                                              attribute:NSLayoutAttributeWidth
                                                                              relatedBy:NSLayoutRelationEqual
                                                                                 toItem:_StarLabel
                                                                              attribute:NSLayoutAttributeHeight
                                                                             multiplier:7.0f
                                                                               constant:0];
    
    topConstranintforStar.active=YES;
    bottomConstrainforStar.active=YES;
    leftConstrainforStar.active=YES;
    lengthConstrainforStar.active=YES;
    [self.StarLabel setLevel:3];
    
    
    //set constrains for distance label
    _DistanceLabel.translatesAutoresizingMaskIntoConstraints=NO;
    NSLayoutConstraint *topConstrainforDistance=[NSLayoutConstraint constraintWithItem:_DistanceLabel
                                                                            attribute:NSLayoutAttributeTop
                                                                            relatedBy:NSLayoutRelationEqual
                                                                               toItem:self.contentView
                                                                            attribute:NSLayoutAttributeTop
                                                                           multiplier:1.0f
                                                                             constant:width*451/640];
    
    NSLayoutConstraint *buttomConstrainforDistance =[NSLayoutConstraint constraintWithItem:_DistanceLabel
                                                                                 attribute:NSLayoutAttributeBottom
                                                                                 relatedBy:NSLayoutRelationEqual
                                                                                    toItem:self.contentView
                                                                                 attribute:NSLayoutAttributeBottom
                                                                                multiplier:1.0f
                                                                                  constant:0-width*30/640];
    
    NSLayoutConstraint *leftConstrainforDistance = [NSLayoutConstraint constraintWithItem:_DistanceLabel
                                                                            attribute:NSLayoutAttributeLeading
                                                                            relatedBy:NSLayoutRelationEqual
                                                                               toItem:self.contentView
                                                                            attribute:NSLayoutAttributeLeading
                                                                           multiplier:1.0f
                                                                             constant:width*472/640];
    
    NSLayoutConstraint *rightConstrainforDistance = [NSLayoutConstraint constraintWithItem:_DistanceLabel
                                                                                attribute:NSLayoutAttributeTrailing
                                                                                relatedBy:NSLayoutRelationEqual
                                                                                   toItem:self.contentView
                                                                                attribute:NSLayoutAttributeTrailing
                                                                               multiplier:1.0f
                                                                                 constant:0];
    buttomConstrainforDistance.active=YES;
    topConstrainforDistance.active=YES;
    leftConstrainforDistance.active=YES;
    rightConstrainforDistance.active=YES;
    self.DistanceLabel.text=@"10.1km";
    [self.DistanceLabel setTextAlignment:NSTextAlignmentCenter];
    self.DistanceLabel.font=[UIFont boldSystemFontOfSize:width*25/640];
    self.DistanceLabel.textColor=[UIColor colorWithRed:145/255.0 green:146/255.0 blue:147/255.0 alpha:1];
    
    
    //constrain for store button
    _StoreButton.translatesAutoresizingMaskIntoConstraints=NO;
    NSLayoutConstraint *topConstrainforStore =[NSLayoutConstraint constraintWithItem:_StoreButton
                                                                           attribute:NSLayoutAttributeTop
                                                                           relatedBy:NSLayoutRelationEqual
                                                                              toItem:self.contentView
                                                                           attribute:NSLayoutAttributeTop
                                                                          multiplier:1.0f
                                                                            constant:width*30/640];
    
    NSLayoutConstraint *rightConstrainforStore =[NSLayoutConstraint constraintWithItem:_StoreButton
                                                                           attribute:NSLayoutAttributeTrailing
                                                                           relatedBy:NSLayoutRelationEqual
                                                                              toItem:self.contentView
                                                                           attribute:NSLayoutAttributeTrailing
                                                                          multiplier:1.0f
                                                                            constant:0-width*30/640];
    
    NSLayoutConstraint *equalConstrainforStore =[NSLayoutConstraint constraintWithItem:_StoreButton
                                                                             attribute:NSLayoutAttributeWidth
                                                                             relatedBy:NSLayoutRelationEqual
                                                                                toItem:nil
                                                                             attribute:NSLayoutAttributeNotAnAttribute
                                                                            multiplier:1.0f
                                                                              constant:width*52/640];
    
    NSLayoutConstraint *heightConstrainforStore =[NSLayoutConstraint constraintWithItem:_StoreButton
                                                                              attribute:NSLayoutAttributeHeight
                                                                              relatedBy:NSLayoutRelationEqual
                                                                                 toItem:nil
                                                                              attribute:NSLayoutAttributeNotAnAttribute
                                                                             multiplier:1.0f
                                                                               constant:width*45/640];
    
    topConstrainforStore.active=YES;
    rightConstrainforStore.active=YES;
    equalConstrainforStore.active=YES;
    heightConstrainforStore.active=YES;
    
    _StoreButton.backgroundColor=[UIColor greenColor];
    _StoreButton.titleLabel.text=@"store";
}




-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    self.contentView.layer.borderWidth=1.0f;
    self.contentView.layer.borderColor=[[UIColor grayColor] CGColor];

        return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


@end
